<?php
/*
 * Camelot PHP Tools
 *
 * @version 2.0
 * @author Bendsoft
 * @package PHP Tools
 * @subpackage Camelot
 * @license FreeBSD License (www.bendsoft.com/licensing/)
 *
 */

class CamelotContent extends Db {

    public $camelot_content_id = 0;
    public $camelot_content_camelot_list_id = 0;
    public $camelot_content_camelot_list_id_external = 0;
    public $camelot_content_row_index = 0;
    public $camelot_content_content = 0;

    public function open($id) {
        if (is_numeric($id)) {
            $sql = "SELECT * FROM camelot_content WHERE camelot_content_id = '$id'";
            $res = parent::DB_SELECT($sql);
            if (mysql_num_rows($res) <> 1) {
                return 0;
            }
        } else {
            $sql = "SELECT * FROM camelot_content " . $id;
            $res = parent::DB_SELECT($sql);
            if (mysql_num_rows($res) <= 0) {
                return 0;
            }
        }


        $data = array();
        while ($row = mysql_fetch_array($res)) {
            $this->camelot_content_id = $row['camelot_content_id'];
            $this->camelot_content_camelot_list_id = $row['camelot_content_camelot_list_id'];
            $this->camelot_content_camelot_list_id_external = $row['camelot_content_camelot_list_id_external'];
            $this->camelot_content_row_index = $row['camelot_content_row_index'];
            $this->camelot_content_content = $row['camelot_content_content'];
            $data[] = (array) $this;
        }
        return $data;
    }

    public function save($id) {
        if ($id > 0) {
            $sql = "UPDATE camelot_content SET camelot_content_camelot_list_id = '$this->camelot_content_camelot_list_id', camelot_content_camelot_list_id_external = '$this->camelot_content_camelot_list_id_external', camelot_content_row_index = '$this->camelot_content_row_index', camelot_content_content = '$this->camelot_content_content' WHERE camelot_content_id = '$id'";
            $res = parent::DB_UPDATE($sql);
        } else {
            $sql = "INSERT INTO camelot_content (camelot_content_camelot_list_id, camelot_content_camelot_list_id_external, camelot_content_row_index, camelot_content_content) VALUES ('$this->camelot_content_camelot_list_id', '$this->camelot_content_camelot_list_id_external', '$this->camelot_content_row_index', '$this->camelot_content_content')";
            $res = parent::DB_INSERT($sql);
        }
        if ($res != 0 || !$res)
            $res = mysql_insert_id();# Instead of RETURNING
        return $res;
    }

    public function update($indata) {
        $sql = "UPDATE camelot_content SET $indata";
        $res = parent::DB_UPDATE($sql);
        if ($res != 0 || !$res)
            $res = mysql_insert_id();# Instead of RETURNING
        return $res;
    }

    public function delete($id) {
        $sql = "DELETE FROM camelot_content WHERE camelot_content_id = '$id'";
        $res = parent::DB_DELETE($sql);
        return $res;
    }


    public function setCamelotContentId($camelot_content_id) { $this->camelot_content_id = addslashes($camelot_content_id); }
    public function getCamelotContentId() { return stripslashes($this->camelot_content_id); }

    public function setCamelotContentCamelotListId($camelot_content_camelot_list_id) { $this->camelot_content_camelot_list_id = addslashes($camelot_content_camelot_list_id); }
    public function getCamelotContentCamelotListId() { return stripslashes($this->camelot_content_camelot_list_id); }

    public function setCamelotContentCamelotListIdExternal($camelot_content_camelot_list_id_external) { $this->camelot_content_camelot_list_id_external = addslashes($camelot_content_camelot_list_id_external); }
    public function getCamelotContentCamelotListIdExternal() { return stripslashes($this->camelot_content_camelot_list_id_external); }

    public function setCamelotContentRowIndex($camelot_content_row_index) { $this->camelot_content_row_index = addslashes($camelot_content_row_index); }
    public function getCamelotContentRowIndex() { return stripslashes($this->camelot_content_row_index); }

    public function setCamelotContentContent($camelot_content_content) { $this->camelot_content_content = addslashes($camelot_content_content); }
    public function getCamelotContentContent() { return stripslashes($this->camelot_content_content); }

}
?>
